package com.basic.java.threads.sleep;


/**
 * 模拟网络延时类: 放大问题的发生性
 * 创建时间：2022/4/18 22:36
 *
 * @author gejin
 */
public class TestSleep implements Runnable {
    private int nums = 10;

    @Override
    public void run() {
        while (true) {
            if (nums <= 0) {
                break;
            }
            try {
                Thread.sleep(100);

            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "--->拿到了第" + (nums--) + " 张票");
        }
    }

    public static void main(String[] args) {
        TestSleep ticket1 = new TestSleep();

        new Thread(ticket1, "小米").start();
        new Thread(ticket1, "OPPO").start();
        new Thread(ticket1, "VIVO").start();
        new Thread(ticket1, "MEIZU").start();
    }
}

